package com.yangst.service.ribbon.service.Impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yangst.service.ribbon.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created by YST on 2018/4/17.
 */
@Service
public class HelloServiceImpl implements HelloService{
    @Autowired
    RestTemplate restTemplate;

    /*
    添加熔断配置
     */
    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name) {
        return restTemplate.getForObject("http://CLOUD-SERVICE-USER/hi?name="+name,String.class);
    }

    public String hiError(String name){
        return "hi,"+name+",sorry,error!";
    }
}
